package com.mapper;

import com.pojo.ProductOrder;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 产品订单映射器
 *
 * @author 蔡文欣
 * @date 2023/07/01 09:17:19
 */
@Mapper
public interface ProductOrderMapper {
    /**
     * 查询产品订单
     *
     * @return {@link List}<{@link ProductOrder}>
     */
    @Select("select id," +
            "sales_order_status salesOrderStatus ," +
            " sales_order_no salesOrderNo," +
            " product_id productId, " +
            "product_name productName, " +
            "product_number productNumber ," +
            "custom_name customName, " +
            "custom_address customAddress," +
            "custom_phone customPhone," +
            "product_order_code productOrderCode," +
            "product_order_status productOrderStatus," +
            "size_id sizeId" +
            " from product_order")
    List<ProductOrder> QueryAll();

    /**
     * 添加产品订单
     *
     * @return int
     */
    @Insert("INSERT INTO product_order VALUES (default,10,#{salesOrderNo}" +
            ",#{productId},#{productName},#{productNumber}," +
            "#{customName},#{customAddress},#{customPhone},#{productOrderCode}," +
            "#{productOrderStatus},#{sizeId},#{categoryId},#{productMaterial}," +
            "#{productOrderTime},null)")
    int addProductOrder(ProductOrder productOrder);

    /**
     * 按ID查询产品订单
     *
     * @param id ID
     * @return {@link ProductOrder}
     */
    @Select(" select id, sales_order_status salesOrderStatus, sales_order_no salesOrderNo, product_id productId, product_name productName, product_number productNumber, custom_name customName, custom_address customAddress, custom_phone customPhone, product_order_code productOrderCode, product_order_status productOrderStatus, size_id sizeId, category_id categoryId, product_material productMaterial from product_order where id=#{id}")
    ProductOrder queryProductOrderById(Long id);

    /**
     * 更新状态
     *
     * @param id ID
     * @return {@link Integer}
     */
    @Update("update product_order set  product_order_status=#{status} where id=#{id}")
    Integer updateStatus(@Param("id") Long id, @Param("status") Integer status);


    /**
     * 查询产品id
     *
     * @param id id
     * @return {@link ProductOrder}
     */
    @Select("select * from product_order where product_id=#{id}")
    ProductOrder queryProductId(Long id);

    /**
     * 添加成品
     *
     * @param productId           产品标识
     * @param number              编号
     * @param size                尺寸
     * @param category            类别
     * @param productionOrderCode 生产订单代码
     * @param material            材料
     * @param state               州
     * @return int
     */
    @Insert("INSERT INTO hua_production_order \n" +
            "(\n" +
            "    id,\n" +
            "    production_order_code,\n" +
            "    production_size,\n" +
            "    production_material,\n" +
            "    production_category,\n" +
            "    product_id,\n" +
            "    create_time,\n" +
            "    update_time,\n" +
            "    end_time,\n" +
            "    state,\n" +
            "    product_num\n" +
            ") \n" +
            "VALUES\n" +
            "(\n" +
            "    DEFAULT,\n" +
            "    #{productionOrderCode}, \n" +
            "    #{size}, \n" +
            "    #{material}, \n" +
            "    #{category}, \n" +
            "    #{productId}, \n" +
            "    NOW(), \n" +
            "    DEFAULT, \n" +
            "    DEFAULT, \n" +
            "    #{state},\n" +
            "    #{number} \n" +
            ");")
    int add(@Param("productId") Long productId, @Param("number") Long number, @Param("size") Long size, @Param("category") Long category
            , @Param("productionOrderCode") String productionOrderCode, @Param("material") Long material, @Param("state") Long state);
}

